%% ANASTASIOU KONSTANTINOS
%% 793

%% MEROS I

%% ASKHSH 1
%% Dinetai ena dianusma a=[2 1 1]', vreite ena orthogwnio dianusma b.
%% Einai monadiko?
% clc;clear;
% a=[2 1 1]
% b=[-2 2 2]'
% a*b

%% Den einai monadiko giati to b mporoume na to pollaplasiasoume
%% me opoiodhpote suntelesth kai na paroume ena neo dianusm alla pali to eswteriko ginomeno
%% me to a tha kanei 0

% clc;clear;
% a = [2 1 1]';
% b = [1 2 -4]';
% c = cross(a,b);
% cross(b,c)
% figure(1);
% clf;
% drawVector([a b c], 'r-', {'a','b','c'});
% view(-160, 7)
% (a')*c % to eswteriko ginomeno mas kanei 0 ara einai orthogwnio sto a
% prosthesame allo ena dianusma.to sunolo paramenei orthogwnio
%  ama prosthetame kai allo ena dianusma tha eixame na lusoume
% ena susthma 4 eksiswsewn me 3 agnwstous to opoio den tha eixe lush.


%% ASKHSH 3
% clc;
% A=[a b c];
% X=sampleUnitSphere(3,200);
% AX=A*X;
% figure(1);clf;hold on;
% plot3(X(1,:),X(2,:),X(3,:),'b.'); view(-60,10)
% plot3(AX(1,:),AX(2,:),AX(3,:),'g.');
% drawVector(A,'r.')
% hold off; axis square equal; grid on;

%% ASKHSH 4
% clc;
% B=[a b c];
% C=diag([1/norm(a) 1/norm(b) 1/norm(c)]);
% A=B*C
% X=sampleUnitSphere(3,200);
% AX=A*X;
% figure(1);clf;hold on;
% plot3(X(1,:),X(2,:),X(3,:),'b.'); view(-60,10)
% plot3(AX(1,:),AX(2,:),AX(3,:),'g.');
% drawVector(A,'r.')
% hold off; axis square equal;grid on;

% optikopoioume thn monadiaia sfaira pou metasxhmatizetai
% gia tous pinakes
% D=AB
clc;
% D=A*B
% X=sampleUnitSphere(3,200);
% DX=A*X;
% figure(1);clf;hold on;
% plot3(X(1,:),X(2,:),X(3,:),'b.'); view(-60,10)
% plot3(DX(1,:),DX(2,:),DX(3,:),'g.');
% drawVector(D,'r.')
% hold off; axis square equal;grid on;

% gia ton pinaka E=AAB
% clc;
% E=A*A*B
% X=sampleUnitSphere(3,200);
% EX=A*X;
% figure(1);clf;hold on;
% plot3(X(1,:),X(2,:),X(3,:),'b.'); view(-60,10)
% plot3(EX(1,:),EX(2,:),EX(3,:),'g.');
% drawVector(E,'r.')
% hold off; axis square equal;grid on;

% gia ton pinaka F=AAAB
% clc;
% F=A*A*A*B
% X=sampleUnitSphere(3,200);
% FX=A*X;
% figure(1);clf;hold on;
% plot3(X(1,:),X(2,:),X(3,:),'b.'); view(-60,10)
% plot3(FX(1,:),FX(2,:),FX(3,:),'g.');
% drawVector(F,'r.')
% hold off; axis square equal;grid on;


%% ASKHSH 5
% A=[1 -1; 1 1]
% sthles se kanonikopoiimenh vash
% A=[0.5 -0.5;0.5 0.5];
% inv(A)


%% 
%% NORMES PINAKWN
%%


%% ASKHSH 1
% clc;clear;
% A=[-2 3;
%     -3 1];
% X=sampleUnitSphere(2,100);
% AX=A*X;
% figure(1);clf;hold on;
% title('pinakes');
% plot(X(1,:),X(2,:),'b.');
% plot(AX(1,:),AX(2,:),'r.');
% hold off
% axis square equal

% B=[1 3;1 1];
% BX=B*X;
% figure(1);hold on;
% plot(X(1,:),X(2,:),'b.');
% plot(BX(1,:),BX(2,:),'r.');
% hold off
% axis square equal

% C=reshape(1:4,2,2);
% CX=C*X;
% figure(1);hold on;
% plot(X(1,:),X(2,:),'b.');
% plot(CX(1,:),CX(2,:),'r.');
% hold off
% axis square equal

%% ASKHSH 2
% clc;
% negB=-B
% negBX=negB*X;
% figure(2);hold on;
% plot(X(1,:),X(2,:),'b.');
% plot(negBX(1,:),negBX(2,:),'r.');
% hold off
% axis square equal
% 
% invB=inv(B);
% invBX=invB*X;
% figure(3);hold on;
% plot(X(1,:),X(2,:),'b.');
% plot(invBX(1,:),invBX(2,:),'r.');
% hold off
% axis square equal


%%
%% PROVOLES
%%

%% ASKHSH 1
clc;clear;
A=[1 0;
    0 1;
    1 0];
a=[1 2 3]';
figure(1);clf;hold on;
drawVector(a,'r.-',{'a'});
P_orth=A*A';
a_orth=P_orth*a;
drawVector([a_orth],'b.-',{'a_{orth}'})
drawSpan(A)
hold off;
view(150,15)

clc;
B=[1 2;
    0 1;
    1 0];
a=[1 2 3]';
figure(1);clf;hold on;
drawVector(a,'r.-',{'a'});
P_orth=B*B';
a_orth=P_orth*a;
drawVector([a_orth],'b.-',{'a_{orth}'})
drawSpan(B)
hold off;
view(150,15)


%% ASKHSH 2
clc;
A=[1 0;
    0 1;
    1 0];
a=[1 2 3]';
n=[-.5 6 3]';
figure(1);clf;hold on;
drawVector(a,'r.-',{'a'});
drawVector(n,'g.-')
P_oblique=A*[1 0 1;0 1 0]*inv([A n]);
a_oblique=P_oblique*a;
drawVector([a_oblique],'b.-',{'a_{oblique}'})
drawSpan(A)
hold off;
view(150,15)

clc;
B=[1 2;
    0 1;
    1 0];
a=[1 2 3]';
n=[-.5 6 3]';
figure(1);clf;hold on;
drawVector(a,'r.-',{'a'});
drawVector(n,'g.-')
P_oblique=B*[1 0 1;2 1 0]*inv([B n]);
a_oblique=P_oblique*a;
drawVector([a_oblique],'b.-',{'a_{oblique}'})
drawSpan(B)
hold off;
view(150,15)


